package com.tjsiqi.service;

import com.google.common.collect.Lists;
import com.tjsiqi.beans.PageQuery;
import com.tjsiqi.beans.PageResult;
import com.tjsiqi.dao.ContractMapper;
import com.tjsiqi.model.Contract;
import com.tjsiqi.util.BeanValidator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;
/**
 * 该功能页已删除
 */
@Service
public class SysContractService {

    @Resource
    private ContractMapper contractMapper;

    public List<Contract> getAll() {
        return contractMapper.getAll();
    }




    public PageResult<Contract> getPage(String conCscUnit, PageQuery pageQuery) {
        BeanValidator.check(pageQuery);
        int count = contractMapper.count();
        if (count > 0) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<Contract> list = contractMapper.getPage(conCscUnit,pageQuery);
            List<Contract> list1 = Lists.newArrayList();
            for (Contract contract: list) {
//                contract.setConSinTime();
               System.out.println( contract.getConSinTime());
            }
            return PageResult.<Contract>builder().total(count).data(list).build();
        }
        return PageResult.<Contract>builder().build();
    }

    public List<String> findCscName() {
        List<String> conCscName = contractMapper.findCscName();
//        System.out.println("---------------"+conCscName.toString());
//        String pro = JSONArray.fromObject(province).toString();
//        System.out.println(pro);
//        ((ServletRequest) response).setCharacterEncoding("utf-8");
//        response.getWriter().println(pro);
        return conCscName;
    }

    public void save(Contract param) {
        contractMapper.insertSelective(param);
        //sysLogService.saveDeptLog(null, dept);
    }
}
